USE [DBQuanLyTrungTamTinHoc]
GO
/****** Object:  StoredProcedure [dbo].[sp_Login]    Script Date: 10/22/2014 11:32:04 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create proc [dbo].[sp_Login]
@tk varchar(50),
@mk varchar(50)
as
	Select COUNT(*) from NguoiDung  
	where TenDangNhap = @tk and MatKhau = @mk
----------------------------------------------------------
	
create proc [dbo].[sp_DoiMatKhau]
@taikhoan varchar(50),
@matkhaucu varchar(50),
@matkhaumoi varchar(50)
As
	If Exists(Select * From NguoiDung Where TenDangNhap = @taikhoan and MatKhau = @matkhaucu 
										or (TenDangNhap  = @taikhoan and MatKhau is null))
	Begin
		Update NguoiDung  set MatKhau = @matkhaumoi   Where TenDangNhap = @taikhoan  
	end
------------------------------------------------
create proc [dbo].[sp_themnguoidung]
@tendangnhap nchar (16),
@machucvu nchar (10),
@tennguoidung nvarchar (50),
@matkhau nchar (16)
as
	if exists (select ChucVu .MaChucVu  
				from NguoiDung inner join ChucVu on NguoiDung .MaChucVu =ChucVu .MaChucVu
				where ChucVu .MaChucVu = @machucvu  )
	insert into NguoiDung (TenDangNhap ,MaChucVu ,TenNguoiDung ,MatKhau )
	values (@tendangnhap  ,@machucvu  ,@tennguoidung  ,@matkhau)
	
----------------------------------------------------------
create proc [dbo].[sp_hocvien_dangky]
@mahv nchar(10),
@tehocvien nvarchar (50),
@gioitinh nvarchar(50),
@ngaysinh date,
@diachi nvarchar(50),
@soDT nchar (15)
as
	insert into HocVien (MaHocVien ,TenHocVien ,GioiTinh ,NgaySinh ,DiaChi ,SoDT)
	values (@mahv ,@tehocvien ,@gioitinh ,@ngaysinh ,@diachi ,@soDT )
---------------------------------
create proc sp_hocvien_select
as
	select *from HocVien
go
----------------------------------
create proc sp_hocvien_update
@mahocvien nchar(10),
@tenhocvien nvarchar(50),
@gioitinh nvarchar (50),
@ngaysinh date,
@diachi nvarchar (100),
@sodienthoai nchar (15)
as
	update HocVien
	set MaHocVien =  @mahocvien ,
	TenHocVien = @tenhocvien ,
	GioiTinh = @gioitinh,
	NgaySinh = @ngaysinh ,
	DiaChi = @diachi ,
	SoDT = @sodienthoai
	where MaHocVien = @mahocvien 
go